const {
	db,
	dbCmd,
	$,
	result_success,
	result_error,
	appletInfoCollection,
	shopieCollection,
	getUuid,
	shopieReportCollection,
	shopieUserReportCollection,
	shopieMonthReportCollection,
	shopieUserMonthReportCollection,
	getCommonTime,
	userCollection
} = require('../../common/constants')


module.exports = async function(params = {}) {
	const token = this.getUniIdToken()
	if (!token) {
		return result_error('登录失效,请重新登录')
	}
	let payload = await this.uniID.checkToken(token)
	if (payload.code) {
		return payload
	}
	let cUser = await userCollection.doc(payload.uid).get()
	cUser = cUser.data[0]
	let role = cUser.role[0]
	if(!cUser.app_id){
		return result_success({})
	}
	//获取当前应用
	let appletInfoData = await appletInfoCollection.doc(cUser.app_id).get()
	appletInfoData = appletInfoData.data[0]
	let app_id = appletInfoData._id
	let shop_id = app_id
	//查询开始时间
	let qSDate = new Date()
	qSDate.setMonth(qSDate.getMonth() - 12)
	qSDate.setDate(1)
	qSDate.setHours(0)
	qSDate.setMinutes(0)
	qSDate.setSeconds(0)
	let qSDateTime = getCommonTime(qSDate).todayStart
	//查询结束时间
	let qEDate = new Date()
	let qEDateTime = getCommonTime(qEDate).todayEnd
	let shopieMonthReports
	let shopieReportData
	if (role === 'shop_admin') {
		//查询收支报表数据
		let shopieReportTotal = await shopieReportCollection.where({
			app_id: app_id,
			shop_id: shop_id,
			date_time: dbCmd.lt(getCommonTime().todayEnd),
			ex_month_report: false
		}).count()
		if (shopieReportTotal.total > 0) {
			let shopieMonthReportTotal = await shopieMonthReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				date_time: dbCmd.gt(qSDateTime).and(dbCmd.lt(qEDateTime))
			}).count()
			if (shopieMonthReportTotal.total !== 12) {
				//设置开始时间
				let dTDate = new Date()
				dTDate.setMonth(dTDate.getMonth() - 12)
				dTDate.setDate(1)
				dTDate.setHours(0)
				dTDate.setMinutes(0)
				dTDate.setSeconds(0)
				let dTDateObj
				let dTDateTime
				for (var i = 0; i <= 12; i++) {
					if (i > 0) {
						dTDate.setMonth(dTDate.getMonth() + 1)
					}
					dTDateObj = getCommonTime(dTDate)
					dTDateTime = dTDateObj.todayStart
					let sYear = dTDateObj.now.year
					let sMonth = dTDateObj.now.month

					let tShopieMonthReport = await db.collection('wmzmall-shopie-month-report').where({
						app_id: app_id,
						shop_id: shop_id,
						year: sYear,
						month: sMonth
					}).get()
					tShopieMonthReport = tShopieMonthReport.data
					if (tShopieMonthReport.length === 0) {
						let data = []
						//获取这个月总共多少天
						let eDate = new Date(dTDate.getTime())
						eDate.setMonth(eDate.getMonth() + 1)
						eDate.setDate(0)
						let totalDate = eDate.getDate()
						for (var j = 1; j <= totalDate; j++) {
							data.push({
								_id: getUuid(),
								index: j,
								year: sYear,
								month: sMonth
							})
						}
						await db.collection('wmzmall-shopie-month-report').add({
							app_id: app_id,
							shop_id: app_id,
							year: sYear,
							month: sMonth,
							shop_id_year_month: app_id + "_" + sYear + "_" + sMonth,
							pay_money: 0,
							pay_count: 0,
							refound_money: 0,
							refound_count: 0,
							count: totalDate,
							money: 0,
							wechat_count: 0,
							alipay_count: 0,
							create_time: new Date().getTime(),
							date_time: dTDateTime,
							data: data,
							wechat_money: 0,
							alipay_money: 0,
							sm_count: 0,
							sm_money: 0,
							lj_count: 0,
							lj_money: 0,
							dd_count: 0,
							dd_money: 0,
							cz_count: 0,
							cz_money: 0,
							hy_count: 0,
							hy_money: 0,
							ye_count: 0,
							ye_money: 0
						})
					}
				}
			}
			let shopieReport = await db.collection('wmzmall-shopie-report').where({
				app_id: app_id,
				shop_id: app_id,
				date_time: dbCmd.lt(getCommonTime().todayStart),
				ex_month_report: false
			}).limit(10).orderBy('date_time', 'asc').get()
			shopieReport = shopieReport.data
			for (var t in shopieReport) {
				let shopie = shopieReport[t]
				let shopieDateTimeObj = getCommonTime(new Date(shopie.date_time))
				let sYear = shopieDateTimeObj.now.year
				let sMonth = shopieDateTimeObj.now.month
				let tShopieMonthReport = await db.collection('wmzmall-shopie-month-report').where({
					app_id: app_id,
					shop_id: shop_id,
					year: sYear,
					month: sMonth
				}).get()
				tShopieMonthReport = tShopieMonthReport.data[0]
				if (tShopieMonthReport) {
					let data = tShopieMonthReport.data
					let shopieDay = shopie.day - 1
					data[shopieDay] = shopie
					let money = 0
					let pay_count = 0
					let pay_money = 0
					let refound_count = 0
					let refound_money = 0
					let wechat_count = 0
					let wechat_money = 0
					let alipay_count = 0
					let alipay_money = 0
					let sm_count = 0
					let sm_money = 0
					let lj_count = 0
					let lj_money = 0
					let dd_count = 0
					let dd_money = 0
					let cz_count = 0
					let cz_money = 0
					let hy_count = 0
					let hy_money = 0
					let ye_count = 0
					let ye_money = 0
					for (var sh = 0; sh <= shopieDay; sh++) {
						if (data[sh].money) {
							money = money + data[sh].money
						}
						if (data[sh].pay_count) {
							pay_count = pay_count + data[sh].pay_count
						}
						if (data[sh].pay_money) {
							pay_money = pay_money + data[sh].pay_money
						}
						if (data[sh].refound_count) {
							refound_count = refound_count + data[sh].refound_count
						}
						if (data[sh].refound_money) {
							refound_money = refound_money + data[sh].refound_money
						}
						if (data[sh].wechat_count) {
							wechat_count = wechat_count + data[sh].wechat_count
						}
						if (data[sh].wechat_money) {
							wechat_money = wechat_money + data[sh].wechat_money
						}
						if (data[sh].alipay_count) {
							alipay_count = alipay_count + data[sh].alipay_count
						}
						if (data[sh].alipay_money) {
							alipay_money = alipay_money + data[sh].alipay_money
						}
						if (data[sh].sm_count) {
							sm_count = sm_count + data[sh].sm_count
						}
						if (data[sh].sm_money) {
							sm_money = sm_money + data[sh].sm_money
						}
						if (data[sh].lj_count) {
							lj_count = lj_count + data[sh].lj_count
						}
						if (data[sh].lj_money) {
							lj_money = lj_money + data[sh].lj_money
						}
						if (data[sh].dd_count) {
							dd_count = dd_count + data[sh].dd_count
						}
						if (data[sh].dd_money) {
							dd_money = dd_money + data[sh].dd_money
						}
						if (data[sh].cz_count) {
							cz_count = cz_count + data[sh].cz_count
						}
						if (data[sh].cz_money) {
							cz_money = cz_money + data[sh].cz_money
						}
						if (data[sh].hy_count) {
							hy_count = hy_count + data[sh].hy_count
						}
						if (data[sh].hy_money) {
							hy_money = hy_money + data[sh].hy_money
						}
						if (data[sh].ye_count) {
							ye_count = ye_count + data[sh].ye_count
						}
						if (data[sh].ye_money) {
							ye_money = ye_money + data[sh].ye_money
						}
					}
					await db.collection('wmzmall-shopie-month-report').doc(tShopieMonthReport._id).update({
						pay_money: money - refound_money,
						pay_count: pay_count,
						refound_money: refound_money,
						refound_count: refound_count,
						money: money,
						alipay_count: alipay_count,
						wechat_count: wechat_count,
						data: data,
						wechat_money: wechat_money,
						alipay_money: alipay_money,
						sm_count: sm_count,
						sm_money: sm_money,
						lj_count: lj_count,
						lj_money: lj_money,
						dd_count: dd_count,
						dd_money: dd_money,
						cz_count: cz_count,
						cz_money: cz_money,
						hy_count: hy_count,
						hy_money: hy_money,
						ye_count: ye_count,
						ye_money: ye_money
					})
					await db.collection('wmzmall-shopie-report').doc(shopie._id).update({
						ex_month_report: true
					})
				}
			}
		}
		shopieMonthReports = await shopieMonthReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				date_time: dbCmd.gte(qSDateTime).and(dbCmd.lt(qEDateTime))
			})
			.orderBy('date_time', 'asc').get()
		shopieMonthReports = shopieMonthReports.data
		//查询今日数据
		let cDateObj = getCommonTime()
		let cYear = cDateObj.now.year
		let cMonth = cDateObj.now.month
		let cDay = cDateObj.now.day
		let queryParams = {
			app_id: appletInfoData._id,
			shop_id: appletInfoData._id,
			year: cYear,
			month: cMonth,
			day: cDay
		};
		shopieReportData = await shopieReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				year: cYear,
				month: cMonth,
				day: cDay
			})
			.get()
		shopieReportData = shopieReportData.data
		if (shopieReportData.length > 0 && shopieMonthReports.length > 0) {
			let shopieMonthReportsObj = shopieMonthReports[shopieMonthReports.length - 1]
			let shopieMonthReportsData = shopieMonthReportsObj.data
			shopieReportData = shopieReportData[0]
			for (var i in shopieMonthReportsData) {
				if (shopieMonthReportsData[i].day === shopieReportData.day || shopieMonthReportsData[i]
					.index ===
					shopieReportData.day) {
					shopieMonthReportsData[i] = shopieReportData
					shopieMonthReports[shopieMonthReports.length - 1].alipay_count = shopieMonthReports[
							shopieMonthReports.length - 1].alipay_count + shopieReportData
						.alipay_count
					shopieMonthReports[shopieMonthReports.length - 1].alipay_money = shopieMonthReports[
							shopieMonthReports.length - 1].alipay_money + shopieReportData
						.alipay_money
					shopieMonthReports[shopieMonthReports.length - 1].cz_count = shopieMonthReports[
						shopieMonthReports.length - 1].cz_count + shopieReportData.cz_count
					shopieMonthReports[shopieMonthReports.length - 1].cz_money = shopieMonthReports[
						shopieMonthReports.length - 1].cz_money + shopieReportData.cz_money
					shopieMonthReports[shopieMonthReports.length - 1].dd_count = shopieMonthReports[
						shopieMonthReports.length - 1].dd_count + shopieReportData.dd_count
					shopieMonthReports[shopieMonthReports.length - 1].dd_money = shopieMonthReports[
						shopieMonthReports.length - 1].dd_money + shopieReportData.dd_money
					shopieMonthReports[shopieMonthReports.length - 1].hy_count = shopieMonthReports[
						shopieMonthReports.length - 1].hy_count + shopieReportData.hy_count
					shopieMonthReports[shopieMonthReports.length - 1].hy_money = shopieMonthReports[
						shopieMonthReports.length - 1].hy_money + shopieReportData.hy_money
					shopieMonthReports[shopieMonthReports.length - 1].lj_count = shopieMonthReports[
						shopieMonthReports.length - 1].lj_count + shopieReportData.lj_count
					shopieMonthReports[shopieMonthReports.length - 1].lj_money = shopieMonthReports[
						shopieMonthReports.length - 1].lj_money + shopieReportData.lj_money
					shopieMonthReports[shopieMonthReports.length - 1].money = shopieMonthReports[
							shopieMonthReports
							.length - 1]
						.money + shopieReportData.money
					shopieMonthReports[shopieMonthReports.length - 1].pay_count = shopieMonthReports[
						shopieMonthReports.length - 1].pay_count + shopieReportData.pay_count
					shopieMonthReports[shopieMonthReports.length - 1].pay_money = shopieMonthReports[
						shopieMonthReports.length - 1].pay_money + shopieReportData.pay_money
					shopieMonthReports[shopieMonthReports.length - 1].refound_count = shopieMonthReports[
							shopieMonthReports.length - 1].refound_count + shopieReportData
						.refound_count
					shopieMonthReports[shopieMonthReports.length - 1].refound_money = shopieMonthReports[
							shopieMonthReports.length - 1].refound_money + shopieReportData
						.refound_money
					shopieMonthReports[shopieMonthReports.length - 1].sm_count = shopieMonthReports[
						shopieMonthReports.length - 1].sm_count + shopieReportData.sm_count
					shopieMonthReports[shopieMonthReports.length - 1].sm_money = shopieMonthReports[
						shopieMonthReports.length - 1].sm_money + shopieReportData.sm_money
					shopieMonthReports[shopieMonthReports.length - 1].wechat_count = shopieMonthReports[
							shopieMonthReports.length - 1].wechat_count + shopieReportData
						.wechat_count
					shopieMonthReports[shopieMonthReports.length - 1].wechat_money = shopieMonthReports[
							shopieMonthReports.length - 1].wechat_money + shopieReportData
						.wechat_money

					shopieMonthReports[shopieMonthReports.length - 1].ye_count = shopieMonthReports[
							shopieMonthReports.length - 1].ye_count + shopieReportData
						.ye_count
					shopieMonthReports[shopieMonthReports.length - 1].ye_money = shopieMonthReports[
							shopieMonthReports.length - 1].ye_money + shopieReportData
						.ye_money
					break
				}
			}
			shopieMonthReports[shopieMonthReports.length - 1].data = shopieMonthReportsData
		}
	} else {
		//查询收支报表数据
		let shopieReportTotal = await shopieUserReportCollection.where({
			app_id: app_id,
			shop_id: shop_id,
			share_user_id: cUser._id,
			date_time: dbCmd.lt(getCommonTime().todayEnd),
			ex_month_report: false
		}).count()
		if (shopieReportTotal.total > 0) {
			let shopieMonthReportTotal = await shopieUserMonthReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				share_user_id: cUser._id,
				date_time: dbCmd.gt(qSDateTime).and(dbCmd.lt(qEDateTime))
			}).count()
			if (shopieMonthReportTotal.total !== 12) {
				//设置开始时间
				let dTDate = new Date()
				dTDate.setMonth(dTDate.getMonth() - 12)
				dTDate.setDate(1)
				dTDate.setHours(0)
				dTDate.setMinutes(0)
				dTDate.setSeconds(0)
				let dTDateObj
				let dTDateTime
				for (var i = 0; i <= 12; i++) {
					if (i > 0) {
						dTDate.setMonth(dTDate.getMonth() + 1)
					}
					dTDateObj = getCommonTime(dTDate)
					dTDateTime = dTDateObj.todayStart
					let sYear = dTDateObj.now.year
					let sMonth = dTDateObj.now.month

					let tShopieMonthReport = await shopieUserMonthReportCollection.where({
						app_id: app_id,
						shop_id: shop_id,
						year: sYear,
						month: sMonth,
						share_user_id: cUser._id
					}).get()
					tShopieMonthReport = tShopieMonthReport.data
					if (tShopieMonthReport.length === 0) {
						let data = []
						//获取这个月总共多少天
						let eDate = new Date(dTDate.getTime())
						eDate.setMonth(eDate.getMonth() + 1)
						eDate.setDate(0)
						let totalDate = eDate.getDate()
						for (var j = 1; j <= totalDate; j++) {
							data.push({
								_id: getUuid(),
								index: j,
								year: sYear,
								month: sMonth
							})
						}
						await shopieUserMonthReportCollection.add({
							app_id: app_id,
							shop_id: app_id,
							year: sYear,
							month: sMonth,
							shop_id_year_month: app_id + "_" + sYear + "_" + sMonth,
							pay_money: 0,
							pay_count: 0,
							refound_money: 0,
							refound_count: 0,
							count: totalDate,
							money: 0,
							wechat_count: 0,
							alipay_count: 0,
							create_time: new Date().getTime(),
							date_time: dTDateTime,
							data: data,
							wechat_money: 0,
							alipay_money: 0,
							sm_count: 0,
							sm_money: 0,
							lj_count: 0,
							lj_money: 0,
							dd_count: 0,
							dd_money: 0,
							cz_count: 0,
							cz_money: 0,
							hy_count: 0,
							hy_money: 0,
							ye_count: 0,
							ye_money: 0,
							share_user_id: cUser._id,
						})
					}
				}
			}
			let shopieReport = await shopieUserReportCollection.where({
				app_id: app_id,
				shop_id: app_id,
				date_time: dbCmd.lt(getCommonTime().todayStart),
				share_user_id: cUser._id,
				ex_month_report: false
			}).limit(10).orderBy('date_time', 'asc').get()
			shopieReport = shopieReport.data
			for (var t in shopieReport) {
				let shopie = shopieReport[t]
				let shopieDateTimeObj = getCommonTime(new Date(shopie.date_time))
				let sYear = shopieDateTimeObj.now.year
				let sMonth = shopieDateTimeObj.now.month
				let tShopieMonthReport = await shopieUserMonthReportCollection.where({
					app_id: app_id,
					shop_id: shop_id,
					year: sYear,
					month: sMonth,
					share_user_id: cUser._id
				}).get()
				tShopieMonthReport = tShopieMonthReport.data[0]
				if (tShopieMonthReport) {
					let data = tShopieMonthReport.data
					let shopieDay = shopie.day - 1
					data[shopieDay] = shopie
					let money = 0
					let pay_count = 0
					let pay_money = 0
					let refound_count = 0
					let refound_money = 0
					let wechat_count = 0
					let wechat_money = 0
					let alipay_count = 0
					let alipay_money = 0
					let sm_count = 0
					let sm_money = 0
					let lj_count = 0
					let lj_money = 0
					let dd_count = 0
					let dd_money = 0
					let cz_count = 0
					let cz_money = 0
					let hy_count = 0
					let hy_money = 0
					let ye_count=0
					let ye_money=0
					for (var sh = 0; sh <= shopieDay; sh++) {
						if (data[sh].money) {
							money = money + data[sh].money
						}
						if (data[sh].pay_count) {
							pay_count = pay_count + data[sh].pay_count
						}
						if (data[sh].pay_money) {
							pay_money = pay_money + data[sh].pay_money
						}
						if (data[sh].refound_count) {
							refound_count = refound_count + data[sh].refound_count
						}
						if (data[sh].refound_money) {
							refound_money = refound_money + data[sh].refound_money
						}
						if (data[sh].wechat_count) {
							wechat_count = wechat_count + data[sh].wechat_count
						}
						if (data[sh].wechat_money) {
							wechat_money = wechat_money + data[sh].wechat_money
						}
						if (data[sh].alipay_count) {
							alipay_count = alipay_count + data[sh].alipay_count
						}
						if (data[sh].alipay_money) {
							alipay_money = alipay_money + data[sh].alipay_money
						}
						if (data[sh].sm_count) {
							sm_count = sm_count + data[sh].sm_count
						}
						if (data[sh].sm_money) {
							sm_money = sm_money + data[sh].sm_money
						}
						if (data[sh].lj_count) {
							lj_count = lj_count + data[sh].lj_count
						}
						if (data[sh].lj_money) {
							lj_money = lj_money + data[sh].lj_money
						}
						if (data[sh].dd_count) {
							dd_count = dd_count + data[sh].dd_count
						}
						if (data[sh].dd_money) {
							dd_money = dd_money + data[sh].dd_money
						}
						if (data[sh].cz_count) {
							cz_count = cz_count + data[sh].cz_count
						}
						if (data[sh].cz_money) {
							cz_money = cz_money + data[sh].cz_money
						}
						if (data[sh].hy_count) {
							hy_count = hy_count + data[sh].hy_count
						}
						if (data[sh].hy_money) {
							hy_money = hy_money + data[sh].hy_money
						}

						if (data[sh].ye_count) {
							ye_count = ye_count + data[sh].ye_count
						}
						if (data[sh].ye_money) {
							ye_money = ye_money + data[sh].ye_money
						}
					}
					await shopieUserMonthReportCollection.doc(tShopieMonthReport._id).update({
						pay_money: money - refound_money,
						pay_count: pay_count,
						refound_money: refound_money,
						refound_count: refound_count,
						money: money,
						alipay_count: alipay_count,
						wechat_count: wechat_count,
						data: data,
						wechat_money: wechat_money,
						alipay_money: alipay_money,
						sm_count: sm_count,
						sm_money: sm_money,
						lj_count: lj_count,
						lj_money: lj_money,
						dd_count: dd_count,
						dd_money: dd_money,
						cz_count: cz_count,
						cz_money: cz_money,
						hy_count: hy_count,
						hy_money: hy_money,
						ye_count: ye_count,
						ye_money: ye_money
					})
					await shopieUserReportCollection.doc(shopie._id).update({
						ex_month_report: true
					})
				}
			}
		}
		shopieMonthReports = await shopieUserMonthReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				date_time: dbCmd.gte(qSDateTime).and(dbCmd.lt(qEDateTime))
			})
			.orderBy('date_time', 'asc').get()
		shopieMonthReports = shopieMonthReports.data
		//查询今日数据
		let cDateObj = getCommonTime()
		let cYear = cDateObj.now.year
		let cMonth = cDateObj.now.month
		let cDay = cDateObj.now.day
		let queryParams = {
			app_id: appletInfoData._id,
			shop_id: appletInfoData._id,
			year: cYear,
			month: cMonth,
			day: cDay
		};
		shopieReportData = await shopieUserReportCollection.where({
				app_id: app_id,
				shop_id: shop_id,
				year: cYear,
				month: cMonth,
				day: cDay
			})
			.get()
		shopieReportData = shopieReportData.data
		if (shopieReportData.length > 0 && shopieMonthReports.length > 0) {
			let shopieMonthReportsObj = shopieMonthReports[shopieMonthReports.length - 1]
			let shopieMonthReportsData = shopieMonthReportsObj.data
			shopieReportData = shopieReportData[0]
			for (var i in shopieMonthReportsData) {
				if (shopieMonthReportsData[i].day === shopieReportData.day || shopieMonthReportsData[i]
					.index ===
					shopieReportData.day) {
					shopieMonthReportsData[i] = shopieReportData
					shopieMonthReports[shopieMonthReports.length - 1].alipay_count = shopieMonthReports[
							shopieMonthReports.length - 1].alipay_count + shopieReportData
						.alipay_count
					shopieMonthReports[shopieMonthReports.length - 1].alipay_money = shopieMonthReports[
							shopieMonthReports.length - 1].alipay_money + shopieReportData
						.alipay_money
					shopieMonthReports[shopieMonthReports.length - 1].cz_count = shopieMonthReports[
						shopieMonthReports.length - 1].cz_count + shopieReportData.cz_count
					shopieMonthReports[shopieMonthReports.length - 1].cz_money = shopieMonthReports[
						shopieMonthReports.length - 1].cz_money + shopieReportData.cz_money
					shopieMonthReports[shopieMonthReports.length - 1].dd_count = shopieMonthReports[
						shopieMonthReports.length - 1].dd_count + shopieReportData.dd_count
					shopieMonthReports[shopieMonthReports.length - 1].dd_money = shopieMonthReports[
						shopieMonthReports.length - 1].dd_money + shopieReportData.dd_money
					shopieMonthReports[shopieMonthReports.length - 1].hy_count = shopieMonthReports[
						shopieMonthReports.length - 1].hy_count + shopieReportData.hy_count
					shopieMonthReports[shopieMonthReports.length - 1].hy_money = shopieMonthReports[
						shopieMonthReports.length - 1].hy_money + shopieReportData.hy_money
					shopieMonthReports[shopieMonthReports.length - 1].lj_count = shopieMonthReports[
						shopieMonthReports.length - 1].lj_count + shopieReportData.lj_count
					shopieMonthReports[shopieMonthReports.length - 1].lj_money = shopieMonthReports[
						shopieMonthReports.length - 1].lj_money + shopieReportData.lj_money
					shopieMonthReports[shopieMonthReports.length - 1].money = shopieMonthReports[
							shopieMonthReports
							.length - 1]
						.money + shopieReportData.money
					shopieMonthReports[shopieMonthReports.length - 1].pay_count = shopieMonthReports[
						shopieMonthReports.length - 1].pay_count + shopieReportData.pay_count
					shopieMonthReports[shopieMonthReports.length - 1].pay_money = shopieMonthReports[
						shopieMonthReports.length - 1].pay_money + shopieReportData.pay_money
					shopieMonthReports[shopieMonthReports.length - 1].refound_count = shopieMonthReports[
							shopieMonthReports.length - 1].refound_count + shopieReportData
						.refound_count
					shopieMonthReports[shopieMonthReports.length - 1].refound_money = shopieMonthReports[
							shopieMonthReports.length - 1].refound_money + shopieReportData
						.refound_money
					shopieMonthReports[shopieMonthReports.length - 1].sm_count = shopieMonthReports[
						shopieMonthReports.length - 1].sm_count + shopieReportData.sm_count
					shopieMonthReports[shopieMonthReports.length - 1].sm_money = shopieMonthReports[
						shopieMonthReports.length - 1].sm_money + shopieReportData.sm_money
					shopieMonthReports[shopieMonthReports.length - 1].wechat_count = shopieMonthReports[
							shopieMonthReports.length - 1].wechat_count + shopieReportData
						.wechat_count
					shopieMonthReports[shopieMonthReports.length - 1].wechat_money = shopieMonthReports[
							shopieMonthReports.length - 1].wechat_money + shopieReportData
						.wechat_money

					shopieMonthReports[shopieMonthReports.length - 1].ye_count = shopieMonthReports[
							shopieMonthReports.length - 1].ye_count + shopieReportData
						.ye_count
					shopieMonthReports[shopieMonthReports.length - 1].ye_money = shopieMonthReports[
							shopieMonthReports.length - 1].ye_money + shopieReportData
						.ye_money
					break
				}
			}
			shopieMonthReports[shopieMonthReports.length - 1].data = shopieMonthReportsData
		}
	}

	let report_start_time = '00:00:00'
	let report_end_time = '23:59:59'
	if (appletInfoData.report_start_time && appletInfoData.report_end_time && appletInfoData.report_end_time !=
		'23:59:59') {
		report_start_time = appletInfoData.report_start_time
		report_end_time = "次日" + appletInfoData.report_end_time
	}
	//查询付款码
	let qrcode = ''
	let gathering = await db.collection('wmzmall-gathering').where({
		app_id: appletInfoData._id,
		shop_id: appletInfoData._id
	}).get()
	gathering = gathering.data
	if (gathering && gathering.length > 0) {
		qrcode = gathering[0].qrcode
	}
	return result_success({
		name: appletInfoData.shop_name,
		mobile: appletInfoData.user_name,
		user_info: {
			role: cUser.role
		},
		qrcode: qrcode,
		data: shopieMonthReports,
		shopieData: shopieReportData,
		report_start_time: report_start_time,
		report_end_time: report_end_time,
		swiperList: [{
			'img': 'https://mp-6f43e342-c9aa-4b97-a5b5-78216437f65b.cdn.bspapp.com/QQ截图20240322161350.png'
		}],
		noticeList: [{
			img: "https://7463-tcb-0ensdli5proairw00b576-0ad17a-1308293149.tcb.qcloud.la/1709052978420_0.png",
			title: '通知公告',
			time: '02-28'
		}]
	})
}